package com.czxy.service;

import com.czxy.dao.UserMapper;
import com.czxy.domain.User;
import com.czxy.utils.MyBatisUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class UserService {

    public  void del(Integer uid){

        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        int i = mapper.deleteByPrimaryKey(uid);
        MyBatisUtils.commitAndClose();
        System.out.println("删除功能执行完毕，影响行数 "+i);


    }














    public  void  add(User user){

        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        int i = mapper.insert(user);
        MyBatisUtils.commitAndClose();
        System.out.println("新增功能执行完毕，影响行数 "+i);


    }














    public PageInfo  findByPg(int pageNum,int pageSize){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);


        PageHelper.startPage(pageNum,pageSize);

        List<User> users = mapper.selectAll();

        PageInfo<User> pageInfo = new PageInfo<>(users);

        MyBatisUtils.close();


        return pageInfo;

    }












    public  User  findByPk(User user){

        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);

        User u = mapper.selectByPrimaryKey(user);

        MyBatisUtils.close();

        return u;

    }



    public List<User> findAll(){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);

        List<User> users = mapper.selectAll();

        MyBatisUtils.close();

        return users;

    }
}
